package Clothing.serviceImpl.agreement;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import Clothing.bean.request.agreement.GetAgreementRequest;
import Clothing.bean.respose.getAgreementList.GetAgreementListResponse;
import Clothing.bean.respose.getAgreementList.GetAgreementListResponse.AgreementInfo;
import Clothing.dao.AgreementDao;
import Clothing.entity.AgreementAllEntity;
import Clothing.entity.AgreementEntity;
import Clothing.service.agreement.AgreementService;

@Service("agreementService")
public class AgreementServiceImpl implements AgreementService {

    @Autowired
    private AgreementDao agreementDao;
    
    public int getAgreementList(GetAgreementRequest request, GetAgreementListResponse response) {
        List<AgreementInfo> agreementList = new ArrayList<AgreementInfo>();
        List<AgreementAllEntity> agreementAllEntities = null;
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("userName", request.getUserName());
        map.put("agreementId", request.getAgreementId());
        agreementAllEntities = agreementDao.getAll(map);
        if(agreementAllEntities.size() ==0 || agreementAllEntities==null){
            return 1;
        }
        for (AgreementAllEntity agreementAllEntity : agreementAllEntities) {
            AgreementInfo agreementInfo = new AgreementInfo();
            BeanUtils.copyProperties(agreementAllEntity, agreementInfo);
            agreementList.add(agreementInfo);
            
        }
        response.setAgreementList(agreementList);
        return 0;
    }

}
